package 蓝桥.模拟赛;

import java.util.*;

public class Main10_2 {
    public static void main(String[] args) {
//        Scanner in = new Scanner(System.in);
//        int n = in.nextInt();
//        char[] steps = in.next().toCharArray();

        int n = 1000000;
        // 随机使用FLR生成长度为n的字符串
        char[] steps = new char[n];
        char[] vs = {'F', 'L', 'R'};
        for (int i = 0; i < n; i++) {
            steps[i] = vs[new Random().nextInt(0,3)];
        }
        System.out.println(steps);


        // 0,1,2,3分别代表上右下左
        int[][] orientation = {{-1, 0}, {0, 1} ,{1, 0},{0, -1}};
        int orit = 0;   // 初始方向向上
        List<int[]> list = new ArrayList<>();

        // 记录最终的不同位置
        Set<int[]> result_set = new TreeSet<>(
                (o1, o2) -> {
                    if (o1[0] == o2[0]) {
                        return o1[1] - o2[1];
                    }
                    return o1[0] - o2[0];
                }
        );

        int r = 0, c = 0;
        go_init(steps, r, c, orit,list);
        // 改变steps中某一个值
        int last_r = list.get(n-1)[0], last_c = list.get(n-1)[1];
        for (int i = 0; i < steps.length; i++) {
            char temp = steps[i];

            // 直接通过旋转的方式来计算最后的位置
            // 支点
            r = 0;
            c = 0;
            if(i>0){
                r = list.get(i-1)[0];
                c = list.get(i-1)[1];
                orit = list.get(i-1)[2];
            }
            // 左转90度 F -> L, R->F
            if(temp=='F' || temp=='R'){
                int new_r = r - (last_c-c);
                int new_c = c + (last_r-r);
                result_set.add(new int[]{new_r, new_c});
            }

            // 右转90度 L -> F, F -> R
            if(temp=='L' || temp=='F'){
                int new_r = r + (last_c-c);
                int new_c = c - (last_r-r);
                result_set.add(new int[]{new_r, new_c});
            }

            // 旋转180度 L -> R, R -> L
            if(temp=='L' || temp=='R'){
                int new_r = r - (last_r-r);
                int new_c = c - (last_c-c);
                result_set.add(new int[]{new_r, new_c});
            }


        }


//        System.out.println("-----------------");
        System.out.println(result_set.size());
//        result_set.forEach(e -> System.out.println(e[0] + " " + e[1]));
    }

    private static void go_init(char[] steps, int r, int c, int orit, List<int[]> list) {
        int[][] orientation = {{-1, 0}, {0, 1} ,{1, 0},{0, -1}};
        for (char step : steps) {
            switch (step) {
                case 'F':
                    r += orientation[orit][0];
                    c += orientation[orit][1];
                    list.add(new int[]{r, c, orit});
                    break;
                case 'L':
                    orit = (orit - 1 + 4) % 4;
                    r += orientation[orit][0];
                    c += orientation[orit][1];
                    list.add(new int[]{r, c, orit});
                    break;
                case 'R':
                    orit = (orit + 1) % 4;
                    r += orientation[orit][0];
                    c += orientation[orit][1];
                    list.add(new int[]{r, c, orit});
                    break;
            }
        }
    }
}
